// 讨论区相关的getters
export default {
  // 获取讨论列表
  discussions: state => state.discussions,
  
  // 获取讨论详情
  discussionDetail: state => state.discussionDetail,
  
  // 获取回复列表
  replies: state => state.replies,
  
  // 获取加载状态
  loading: state => state.loading,
  
  // 获取保存状态
  saving: state => state.saving,
  
  // 获取删除状态
  deleting: state => state.deleting,
  
  // 获取错误信息
  error: state => state.error,
  
  // 获取当前包名称
  currentPackageName: state => state.currentPackageName,
  
  // 获取分页信息
  pagination: state => ({
    page: state.page,
    limit: state.limit,
    total: state.total,
    totalPages: Math.ceil(state.total / state.limit)
  }),
  
  // 获取过滤器
  filters: state => state.filters,
  
  // 获取讨论数量
  discussionCount: state => state.total,
  
  // 获取回复数量
  replyCount: state => state.replies.length,
  
  // 检查是否有讨论
  hasDiscussions: state => state.discussions.length > 0,
  
  // 检查是否有讨论详情
  hasDiscussionDetail: state => state.discussionDetail !== null,
  
  // 检查是否有回复
  hasReplies: state => state.replies.length > 0,
  
  // 根据ID获取讨论
  getDiscussionById: state => id => state.discussions.find(d => d.id === id),
  
  // 获取最新的讨论
  latestDiscussions: state => [...state.discussions].sort((a, b) => {
    return new Date(b.createdAt || 0) - new Date(a.createdAt || 0)
  }),
  
  // 获取回复最多的讨论
  mostRepliedDiscussions: state => [...state.discussions].sort((a, b) => {
    return (b.replyCount || 0) - (a.replyCount || 0)
  }),
  
  // 获取分页信息字符串
  paginationText: state => {
    const start = (state.page - 1) * state.limit + 1
    const end = Math.min(state.page * state.limit, state.total)
    return `显示 ${start} - ${end} 条，共 ${state.total} 条`
  }
}